package org.example.t07;

import java.util.ArrayList;

/**
 * 京东面试题：一个线程产生了OOM问题，对另一个线程是否会产生影响
 */
public class OomTest {
    ArrayList<Object> list = new ArrayList<>();

    public static void main(String[] args) {
        OomTest oomTest = new OomTest();
        oomTest.n();
        oomTest.m();
    }

    private void m(){
        new Thread(()->{
            try {
                while(true){
                    list.add(new Object());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        },"add").start();
    }

    private void n(){
        new Thread(()->{
            while(true){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(list.size());
            }
        },"get").start();
    }
}
